package com.example.smartall.ui;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.smartall.R;
import com.example.smartall.adapter.SplashVpAdapter;
import com.example.smartall.entity.HospitalCategoryBean;
import com.example.smartall.fragment.Hospital.CommonFragment;
import com.example.smartall.fragment.Hospital.ExpertFragment;
import com.example.smartall.ui.base.BaseActivity;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * 挂号页面
 */
            //HospitalCategoryRegistration
public class HCPRegistrationActivity extends BaseActivity {

    private ImageView imBack;
    private TextView tvTitle;
    private TabLayout tabLayout;
    private ViewPager vp;

    private SplashVpAdapter vpAdapter;
    private List<Fragment> pages;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_hcpregistration);

        init();
        initEvent();
    }

    @Override
    public void init() {
        imBack = (ImageView) findViewById(R.id.im_back);
        tvTitle = (TextView) findViewById(R.id.tv_title);
        tabLayout = (TabLayout) findViewById(R.id.tabLayout);
        vp = (ViewPager) findViewById(R.id.vp);

        //两个tab
        tvTitle.setText("挂号");
        TabLayout.Tab expertTab = tabLayout.newTab();
        expertTab.setText("专家");
        TabLayout.Tab commonTab = tabLayout.newTab();
        commonTab.setText("普通");
        tabLayout.addTab(expertTab);
        tabLayout.addTab(commonTab);

        //两个vp页面
        pages = new ArrayList<>();
        pages.add(new ExpertFragment());
        pages.add(new CommonFragment((HospitalCategoryBean.RowsBean) getIntent().getSerializableExtra("category"),getIntent().getStringExtra("patientName"))); //好长啊

        vpAdapter = new SplashVpAdapter(getSupportFragmentManager(),0,pages,HCPRegistrationActivity.this);
        vp.setAdapter(vpAdapter);
    }

    @Override
    public void initEvent() {
        imBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                HCPRegistrationActivity.this.finish();
            }
        });
        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                vp.setCurrentItem(tabLayout.getSelectedTabPosition());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {}

            @Override
            public void onTabReselected(TabLayout.Tab tab) {}
        });
        vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}

            @Override
            public void onPageSelected(int position) {
                tabLayout.selectTab(tabLayout.getTabAt(position));
            }

            @Override
            public void onPageScrollStateChanged(int state) {}
        });
    }
}